package com.apex.sdk.ui;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatButton;
import androidx.appcompat.widget.Toolbar;

import com.apex.bluetooth.callback.GeneralCallback;
import com.apex.bluetooth.core.EABleManager;
import com.apex.bluetooth.enumeration.EABleConnectState;
import com.apex.bluetooth.enumeration.EABleSportStatus;
import com.apex.bluetooth.model.EABleAppScreenSport;
import com.apex.bluetooth.model.EABleAppSportData;
import com.apex.bluetooth.model.EABleStartAppSports;
import com.apex.sdk.R;
import com.apex.sdk.databinding.ActivityWatchSportBinding;
import com.apex.sdk.dialog.AgeDialog;
import com.apex.sdk.dialog.WaitingDialog;
import com.apex.sdk.dialog.WatchSportTypeDialog;

public class WatchSportActivity extends AppCompatActivity {
    final String TAG = this.getClass().getSimpleName();
    private WaitingDialog waitingDialog;
    private int intervalTime = 5;
    AgeDialog ageDialog;
    WatchSportTypeDialog watchSportTypeDialog;
    int duration;
    int distance;
    int calorie;

    int type = -1;
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            if (msg.what == 0x41) {
                if (waitingDialog != null && waitingDialog.isShowing()) {
                    waitingDialog.dismiss();
                }
                Toast.makeText(WatchSportActivity.this, getString(R.string.operation_succeeded), Toast.LENGTH_SHORT).show();

            } else if (msg.what == 0x42) {
                if (waitingDialog != null && waitingDialog.isShowing()) {
                    waitingDialog.dismiss();
                }
                Toast.makeText(WatchSportActivity.this, getString(R.string.modification_failed), Toast.LENGTH_SHORT).show();
            } else if (msg.what == 0x43 || msg.what == 0x44) {
                if (waitingDialog != null && waitingDialog.isShowing()) {
                    waitingDialog.dismiss();
                }
                boolean success = (boolean) msg.obj;
                if (!success) {
                    Toast.makeText(WatchSportActivity.this, getString(R.string.modification_failed), Toast.LENGTH_SHORT).show();
                }
            } else if (msg.what == 0x86) {
                if (EABleManager.getInstance().getDeviceConnectState() == EABleConnectState.STATE_CONNECTED&&isStart) {
                    EABleAppSportData eaBleAppSportData = new EABleAppSportData();
                    eaBleAppSportData.setDuration(duration += 1);
                    eaBleAppSportData.setDistance(distance +=30 );
                    eaBleAppSportData.setCalorie(calorie+10);
                    EABleManager.getInstance().setData2Watch(eaBleAppSportData, new GeneralCallback() {
                        @Override
                        public void result(boolean b) {
                            if (mHandler != null) {
                                mHandler.sendEmptyMessageDelayed(0x86, 1000);
                            }
                        }

                        @Override
                        public void mutualFail(int i) {

                        }
                    });
                }
            }
        }
    };
    ActivityWatchSportBinding activityWatchSportBinding;
    boolean isStart;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activityWatchSportBinding = ActivityWatchSportBinding.inflate(getLayoutInflater());
        setContentView(activityWatchSportBinding.getRoot());
        activityWatchSportBinding.tool.setNavigationIcon(R.mipmap.exit_page);
        setSupportActionBar(activityWatchSportBinding.tool);
        getSupportActionBar().setTitle(null);
        activityWatchSportBinding.tool.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        activityWatchSportBinding.intervalTime.setText(5 + getString(R.string.second));
        activityWatchSportBinding.intervalTime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ageDialog == null) {
                    ageDialog = new AgeDialog(WatchSportActivity.this);
                    ageDialog.setSelectListener(new AgeDialog.SelectListener() {
                        @Override
                        public void selectData(int sex) {
                            intervalTime = sex;
                            activityWatchSportBinding.intervalTime.setText(sex + getString(R.string.second));

                        }
                    });
                }
                if (!ageDialog.isShowing()) {
                    ageDialog.show();
                }
            }
        });
        activityWatchSportBinding.startMoving.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (type < 1) {
                    return;
                }
                if (EABleManager.getInstance().getDeviceConnectState() == EABleConnectState.STATE_CONNECTED) {
                    EABleAppScreenSport eaBleAppScreenSport = new EABleAppScreenSport();
                    if (type == 1) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ourdoor_walking);
                    } else if (type == 2) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ourdoor_running);
                    } else if (type == 3) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ourdoor_on_foot);
                    } else if (type == 4) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ourdoor_on_mountaineering);
                    } else if (type == 5) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ourdoor_trail_running);
                    } else if (type == 6) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ourdoor_cycling);
                    } else if (type == 7) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.outdoor_swimming);
                    } else if (type == 8) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.indoor_walking);
                    } else if (type == 9) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.indoor_running);
                    } else if (type == 10) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.indoor_exercise);
                    } else if (type == 11) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.indoor_cycling);
                    } else if (type == 12) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.elliptical);
                    } else if (type == 13) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.yoga);
                    } else if (type == 14) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.rowing);
                    } else if (type == 15) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.indoor_swimming);
                    } else if (type == 16) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.od_rock);
                    } else if (type == 17) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.od_skate);
                    } else if (type == 18) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.od_roller);
                    } else if (type == 19) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.od_parkour);
                    } else if (type == 20) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.od_parachute);
                    } else if (type == 21) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_HIT);
                    } else if (type == 22) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_weight);
                    } else if (type == 23) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_plank);
                    } else if (type == 24) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_jumping);
                    } else if (type == 25) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_stair);
                    } else if (type == 26) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_core);
                    } else if (type == 27) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_flex);
                    } else if (type == 28) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_pilates);
                    } else if (type == 29) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_stretch);
                    } else if (type == 30) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_strength);
                    } else if (type == 31) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_cross);
                    } else if (type == 32) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_dumbbell);
                    } else if (type == 33) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_deadlift);
                    } else if (type == 34) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_sit);
                    } else if (type == 35) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_funcition);
                    } else if (type == 36) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_upper);
                    } else if (type == 37) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_lower);
                    } else if (type == 38) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_abs);
                    } else if (type == 39) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_back);
                    } else if (type == 40) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_sailboat);
                    } else if (type == 41) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_sup);
                    } else if (type == 42) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_polo);
                    } else if (type == 43) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_thrash);
                    } else if (type == 44) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_kayak);
                    } else if (type == 45) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_drifting);
                    } else if (type == 46) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_boating);
                    } else if (type == 47) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_fin);
                    } else if (type == 48) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_diving);
                    } else if (type == 49) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_artistic);
                    } else if (type == 50) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_snorkel);
                    } else if (type == 51) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_kitesurfing);
                    } else if (type == 52) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_atv);
                    } else if (type == 53) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_beach);
                    } else if (type == 54) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.dance_dance);
                    } else if (type == 55) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.dance_delly);
                    } else if (type == 56) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.dance_gymnastics);
                    } else if (type == 57) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.dance_aerobics);
                    } else if (type == 58) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.dance_hip_hop);
                    } else if (type == 59) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_boxing);
                    } else if (type == 60) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_wushu);
                    } else if (type == 61) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_wrestling);
                    } else if (type == 62) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_taichi);
                    } else if (type == 63) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_muay_thai);
                    } else if (type == 64) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_judo);
                    } else if (type == 65) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_taekwondo);
                    } else if (type == 66) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_karate);
                    } else if (type == 67) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_free_sparring);
                    } else if (type == 68) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_soccer);
                    } else if (type == 69) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_basketball);
                    } else if (type == 70) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_volleyball);
                    } else if (type == 71) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_badminton);
                    } else if (type == 72) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_pingpong);
                    } else if (type == 73) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_cricket);
                    } else if (type == 74) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_football);
                    } else if (type == 75) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_racqurball);
                    } else if (type == 76) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_handball);
                    } else if (type == 77) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_squash);
                    } else if (type == 78) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_shuttlecock);
                    } else if (type == 79) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_raga);
                    } else if (type == 80) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.snow_board);
                    } else if (type == 81) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.snow_skis);
                    } else if (type == 82) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.snow_puck);
                    } else if (type == 83) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.snow_skate);
                    } else if (type == 84) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.snow_curling);
                    } else if (type == 85) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.snow_mobile);
                    } else if (type == 86) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.snow_sled);
                    } else if (type == 87) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_meditation);
                    } else if (type == 88) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_kendo);
                    } else if (type == 89) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_fence);
                    } else if (type == 90) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_bowling);
                    } else if (type == 91) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_billiards);
                    } else if (type == 92) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_archery);
                    } else if (type == 93) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_darts);
                    } else if (type == 94) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_horse);
                    } else if (type == 95) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_hula);
                    } else if (type == 96) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_kite);
                    } else if (type == 97) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_fishing);
                    } else if (type == 98) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_fribee);
                    } else if (type == 99) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_equestrian);
                    } else if (type == 100) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_racing);
                    } else if (type == 101) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.other_free);
                    } else if (type == 102) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.other_rope);
                    } else if (type == 103) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.other_climb);
                    } else if (type == 104) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.other_push);
                    } else if (type == 105) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.other_horizontal);
                    } else if (type == 106) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.other_parallel);
                    } else if (type == 107) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.tennis);
                    } else if (type == 108) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.baseball);
                    } else if (type == 109) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.hockey);
                    } else if (type == 110) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.custom_sport);
                    } else if (type == 111) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.mark_time);
                    } else if (type == 112) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.walking_machine);
                    } else if (type == 113) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.athletics);
                    } else if (type == 114) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.lumbar_abdomen_training);
                    } else if (type == 115) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.latin_dance);
                    } else if (type == 116) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ballet);
                    } else if (type == 117) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.golf);
                    } else if (type == 118) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.folk_dance);
                    } else if (type == 119) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.lacrosse);
                    } else if (type == 120) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.softball);
                    } else if (type == 121) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.peak_ball);
                    } else if (type == 122) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.trampoline);
                    } else if (type == 123) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.parkour);
                    } else if (type == 124) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.push_up);
                    } else if (type == 125) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.high_jump);
                    } else {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.long_jump);
                    }
                    eaBleAppScreenSport.setEaBleSportStatus(EABleSportStatus.start);
                    eaBleAppScreenSport.setInterval(intervalTime);
                    if (waitingDialog == null) {
                        waitingDialog = new WaitingDialog(WatchSportActivity.this);
                    }
                    if (!waitingDialog.isShowing()) {
                        waitingDialog.show();
                    }
                    EABleManager.getInstance().startAppScreenSport(eaBleAppScreenSport, new GeneralCallback() {
                        @Override
                        public void result(boolean success) {
                            if (mHandler != null) {
                                Message message = new Message();
                                message.what = 0x41;
                                message.arg2 = 1;
                                mHandler.sendMessage(message);
                            }
                        }

                        @Override
                        public void mutualFail(int errorCode) {
                            Log.e(TAG, "开启手表运动错误码:" + errorCode);
                            if (mHandler != null) {
                                Message message = new Message();
                                message.what = 0x42;
                                message.arg2 = 1;
                                mHandler.sendMessage(message);
                            }
                        }
                    });
                }
            }
        });
        activityWatchSportBinding.endMoving.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (EABleManager.getInstance().getDeviceConnectState() == EABleConnectState.STATE_CONNECTED&&isStart) {
                    EABleStartAppSports eaBleStartAppSports = new EABleStartAppSports();
                    eaBleStartAppSports.setSportStatus(EABleSportStatus.close);
                    /**

                    if (waitingDialog == null) {
                        waitingDialog = new WaitingDialog(WatchSportActivity.this);
                    }
                    if (!waitingDialog.isShowing()) {
                        waitingDialog.show();
                    }
                     */
                    EABleManager.getInstance().startAppSport(eaBleStartAppSports, new GeneralCallback() {
                        @Override
                        public void result(boolean b) {
                            isStart = false;
                        }

                        @Override
                        public void mutualFail(int i) {

                        }
                    });

                }

            }
        });
        activityWatchSportBinding.pauseMoving.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (EABleManager.getInstance().getDeviceConnectState() == EABleConnectState.STATE_CONNECTED) {
                    EABleAppScreenSport eaBleAppScreenSport = new EABleAppScreenSport();
                    if (type == 1) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ourdoor_walking);
                    } else if (type == 2) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ourdoor_running);
                    } else if (type == 3) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ourdoor_on_foot);
                    } else if (type == 4) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ourdoor_on_mountaineering);
                    } else if (type == 5) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ourdoor_trail_running);
                    } else if (type == 6) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ourdoor_cycling);
                    } else if (type == 7) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.outdoor_swimming);
                    } else if (type == 8) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.indoor_walking);
                    } else if (type == 9) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.indoor_running);
                    } else if (type == 10) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.indoor_exercise);
                    } else if (type == 11) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.indoor_cycling);
                    } else if (type == 12) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.elliptical);
                    } else if (type == 13) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.yoga);
                    } else if (type == 14) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.rowing);
                    } else if (type == 15) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.indoor_swimming);
                    } else if (type == 16) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.od_rock);
                    } else if (type == 17) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.od_skate);
                    } else if (type == 18) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.od_roller);
                    } else if (type == 19) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.od_parkour);
                    } else if (type == 20) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.od_parachute);
                    } else if (type == 21) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_HIT);
                    } else if (type == 22) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_weight);
                    } else if (type == 23) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_plank);
                    } else if (type == 24) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_jumping);
                    } else if (type == 25) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_stair);
                    } else if (type == 26) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_core);
                    } else if (type == 27) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_flex);
                    } else if (type == 28) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_pilates);
                    } else if (type == 29) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_stretch);
                    } else if (type == 30) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_strength);
                    } else if (type == 31) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_cross);
                    } else if (type == 32) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_dumbbell);
                    } else if (type == 33) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_deadlift);
                    } else if (type == 34) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_sit);
                    } else if (type == 35) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_funcition);
                    } else if (type == 36) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_upper);
                    } else if (type == 37) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_lower);
                    } else if (type == 38) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_abs);
                    } else if (type == 39) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_back);
                    } else if (type == 40) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_sailboat);
                    } else if (type == 41) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_sup);
                    } else if (type == 42) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_polo);
                    } else if (type == 43) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_thrash);
                    } else if (type == 44) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_kayak);
                    } else if (type == 45) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_drifting);
                    } else if (type == 46) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_boating);
                    } else if (type == 47) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_fin);
                    } else if (type == 48) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_diving);
                    } else if (type == 49) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_artistic);
                    } else if (type == 50) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_snorkel);
                    } else if (type == 51) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_kitesurfing);
                    } else if (type == 52) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_atv);
                    } else if (type == 53) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_beach);
                    } else if (type == 54) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.dance_dance);
                    } else if (type == 55) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.dance_delly);
                    } else if (type == 56) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.dance_gymnastics);
                    } else if (type == 57) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.dance_aerobics);
                    } else if (type == 58) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.dance_hip_hop);
                    } else if (type == 59) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_boxing);
                    } else if (type == 60) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_wushu);
                    } else if (type == 61) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_wrestling);
                    } else if (type == 62) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_taichi);
                    } else if (type == 63) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_muay_thai);
                    } else if (type == 64) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_judo);
                    } else if (type == 65) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_taekwondo);
                    } else if (type == 66) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_karate);
                    } else if (type == 67) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_free_sparring);
                    } else if (type == 68) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_soccer);
                    } else if (type == 69) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_basketball);
                    } else if (type == 70) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_volleyball);
                    } else if (type == 71) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_badminton);
                    } else if (type == 72) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_pingpong);
                    } else if (type == 73) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_cricket);
                    } else if (type == 74) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_football);
                    } else if (type == 75) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_racqurball);
                    } else if (type == 76) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_handball);
                    } else if (type == 77) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_squash);
                    } else if (type == 78) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_shuttlecock);
                    } else if (type == 79) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_raga);
                    } else if (type == 80) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.snow_board);
                    } else if (type == 81) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.snow_skis);
                    } else if (type == 82) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.snow_puck);
                    } else if (type == 83) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.snow_skate);
                    } else if (type == 84) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.snow_curling);
                    } else if (type == 85) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.snow_mobile);
                    } else if (type == 86) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.snow_sled);
                    } else if (type == 87) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_meditation);
                    } else if (type == 88) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_kendo);
                    } else if (type == 89) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_fence);
                    } else if (type == 90) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_bowling);
                    } else if (type == 91) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_billiards);
                    } else if (type == 92) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_archery);
                    } else if (type == 93) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_darts);
                    } else if (type == 94) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_horse);
                    } else if (type == 95) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_hula);
                    } else if (type == 96) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_kite);
                    } else if (type == 97) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_fishing);
                    } else if (type == 98) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_fribee);
                    } else if (type == 99) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_equestrian);
                    } else if (type == 100) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_racing);
                    } else if (type == 101) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.other_free);
                    } else if (type == 102) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.other_rope);
                    } else if (type == 103) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.other_climb);
                    } else if (type == 104) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.other_push);
                    } else if (type == 105) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.other_horizontal);
                    } else if (type == 106) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.other_parallel);
                    } else if (type == 107) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.tennis);
                    } else if (type == 108) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.baseball);
                    } else if (type == 109) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.hockey);
                    } else if (type == 110) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.custom_sport);
                    } else if (type == 111) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.mark_time);
                    } else if (type == 112) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.walking_machine);
                    } else if (type == 113) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.athletics);
                    } else if (type == 114) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.lumbar_abdomen_training);
                    } else if (type == 115) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.latin_dance);
                    } else if (type == 116) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ballet);
                    } else if (type == 117) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.golf);
                    } else if (type == 118) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.folk_dance);
                    } else if (type == 119) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.lacrosse);
                    } else if (type == 120) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.softball);
                    } else if (type == 121) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.peak_ball);
                    } else if (type == 122) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.trampoline);
                    } else if (type == 123) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.parkour);
                    } else if (type == 124) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.push_up);
                    } else if (type == 125) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.high_jump);
                    } else {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.long_jump);
                    }
                    eaBleAppScreenSport.setEaBleSportStatus(EABleSportStatus.pause);
                    eaBleAppScreenSport.setInterval(intervalTime);
                    if (waitingDialog == null) {
                        waitingDialog = new WaitingDialog(WatchSportActivity.this);
                    }
                    if (!waitingDialog.isShowing()) {
                        waitingDialog.show();
                    }
                    EABleManager.getInstance().startAppScreenSport(eaBleAppScreenSport, new GeneralCallback() {
                        @Override
                        public void result(boolean success) {
                            if (mHandler != null) {
                                Message message = new Message();
                                message.what = 0x41;
                                message.arg2 = 3;
                                mHandler.sendMessage(message);
                            }
                        }

                        @Override
                        public void mutualFail(int errorCode) {
                            if (mHandler != null) {
                                Message message = new Message();
                                message.what = 0x42;
                                message.arg2 = 3;
                                mHandler.sendMessage(message);
                            }
                        }
                    });
                }
            }
        });
        activityWatchSportBinding.processMoving.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (EABleManager.getInstance().getDeviceConnectState() == EABleConnectState.STATE_CONNECTED) {
                    EABleAppScreenSport eaBleAppScreenSport = new EABleAppScreenSport();
                    if (type == 1) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ourdoor_walking);
                    } else if (type == 2) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ourdoor_running);
                    } else if (type == 3) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ourdoor_on_foot);
                    } else if (type == 4) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ourdoor_on_mountaineering);
                    } else if (type == 5) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ourdoor_trail_running);
                    } else if (type == 6) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ourdoor_cycling);
                    } else if (type == 7) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.outdoor_swimming);
                    } else if (type == 8) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.indoor_walking);
                    } else if (type == 9) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.indoor_running);
                    } else if (type == 10) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.indoor_exercise);
                    } else if (type == 11) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.indoor_cycling);
                    } else if (type == 12) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.elliptical);
                    } else if (type == 13) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.yoga);
                    } else if (type == 14) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.rowing);
                    } else if (type == 15) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.indoor_swimming);
                    } else if (type == 16) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.od_rock);
                    } else if (type == 17) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.od_skate);
                    } else if (type == 18) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.od_roller);
                    } else if (type == 19) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.od_parkour);
                    } else if (type == 20) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.od_parachute);
                    } else if (type == 21) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_HIT);
                    } else if (type == 22) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_weight);
                    } else if (type == 23) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_plank);
                    } else if (type == 24) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_jumping);
                    } else if (type == 25) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_stair);
                    } else if (type == 26) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_core);
                    } else if (type == 27) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_flex);
                    } else if (type == 28) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_pilates);
                    } else if (type == 29) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_stretch);
                    } else if (type == 30) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_strength);
                    } else if (type == 31) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_cross);
                    } else if (type == 32) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_dumbbell);
                    } else if (type == 33) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_deadlift);
                    } else if (type == 34) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_sit);
                    } else if (type == 35) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_funcition);
                    } else if (type == 36) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_upper);
                    } else if (type == 37) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_lower);
                    } else if (type == 38) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_abs);
                    } else if (type == 39) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.train_back);
                    } else if (type == 40) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_sailboat);
                    } else if (type == 41) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_sup);
                    } else if (type == 42) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_polo);
                    } else if (type == 43) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_thrash);
                    } else if (type == 44) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_kayak);
                    } else if (type == 45) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_drifting);
                    } else if (type == 46) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_boating);
                    } else if (type == 47) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_fin);
                    } else if (type == 48) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_diving);
                    } else if (type == 49) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_artistic);
                    } else if (type == 50) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_snorkel);
                    } else if (type == 51) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_kitesurfing);
                    } else if (type == 52) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_atv);
                    } else if (type == 53) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.water_beach);
                    } else if (type == 54) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.dance_dance);
                    } else if (type == 55) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.dance_delly);
                    } else if (type == 56) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.dance_gymnastics);
                    } else if (type == 57) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.dance_aerobics);
                    } else if (type == 58) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.dance_hip_hop);
                    } else if (type == 59) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_boxing);
                    } else if (type == 60) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_wushu);
                    } else if (type == 61) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_wrestling);
                    } else if (type == 62) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_taichi);
                    } else if (type == 63) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_muay_thai);
                    } else if (type == 64) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_judo);
                    } else if (type == 65) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_taekwondo);
                    } else if (type == 66) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_karate);
                    } else if (type == 67) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.fight_free_sparring);
                    } else if (type == 68) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_soccer);
                    } else if (type == 69) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_basketball);
                    } else if (type == 70) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_volleyball);
                    } else if (type == 71) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_badminton);
                    } else if (type == 72) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_pingpong);
                    } else if (type == 73) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_cricket);
                    } else if (type == 74) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_football);
                    } else if (type == 75) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_racqurball);
                    } else if (type == 76) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_handball);
                    } else if (type == 77) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_squash);
                    } else if (type == 78) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_shuttlecock);
                    } else if (type == 79) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ball_raga);
                    } else if (type == 80) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.snow_board);
                    } else if (type == 81) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.snow_skis);
                    } else if (type == 82) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.snow_puck);
                    } else if (type == 83) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.snow_skate);
                    } else if (type == 84) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.snow_curling);
                    } else if (type == 85) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.snow_mobile);
                    } else if (type == 86) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.snow_sled);
                    } else if (type == 87) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_meditation);
                    } else if (type == 88) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_kendo);
                    } else if (type == 89) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_fence);
                    } else if (type == 90) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_bowling);
                    } else if (type == 91) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_billiards);
                    } else if (type == 92) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_archery);
                    } else if (type == 93) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_darts);
                    } else if (type == 94) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_horse);
                    } else if (type == 95) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_hula);
                    } else if (type == 96) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_kite);
                    } else if (type == 97) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_fishing);
                    } else if (type == 98) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_fribee);
                    } else if (type == 99) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_equestrian);
                    } else if (type == 100) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.leisure_racing);
                    } else if (type == 101) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.other_free);
                    } else if (type == 102) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.other_rope);
                    } else if (type == 103) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.other_climb);
                    } else if (type == 104) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.other_push);
                    } else if (type == 105) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.other_horizontal);
                    } else if (type == 106) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.other_parallel);
                    } else if (type == 107) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.tennis);
                    } else if (type == 108) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.baseball);
                    } else if (type == 109) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.hockey);
                    } else if (type == 110) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.custom_sport);
                    } else if (type == 111) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.mark_time);
                    } else if (type == 112) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.walking_machine);
                    } else if (type == 113) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.athletics);
                    } else if (type == 114) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.lumbar_abdomen_training);
                    } else if (type == 115) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.latin_dance);
                    } else if (type == 116) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.ballet);
                    } else if (type == 117) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.golf);
                    } else if (type == 118) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.folk_dance);
                    } else if (type == 119) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.lacrosse);
                    } else if (type == 120) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.softball);
                    } else if (type == 121) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.peak_ball);
                    } else if (type == 122) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.trampoline);
                    } else if (type == 123) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.parkour);
                    } else if (type == 124) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.push_up);
                    } else if (type == 125) {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.high_jump);
                    } else {
                        eaBleAppScreenSport.setEaBleAppSportType(EABleAppScreenSport.EABleAppSportType.long_jump);
                    }
                    eaBleAppScreenSport.setEaBleSportStatus(EABleSportStatus.processed);
                    eaBleAppScreenSport.setInterval(intervalTime);
                    if (waitingDialog == null) {
                        waitingDialog = new WaitingDialog(WatchSportActivity.this);
                    }
                    if (!waitingDialog.isShowing()) {
                        waitingDialog.show();
                    }
                    EABleManager.getInstance().startAppScreenSport(eaBleAppScreenSport, new GeneralCallback() {
                        @Override
                        public void result(boolean success) {
                            if (mHandler != null) {
                                Message message = new Message();
                                message.what = 0x41;
                                message.arg2 = 3;
                                mHandler.sendMessage(message);
                            }
                        }

                        @Override
                        public void mutualFail(int errorCode) {
                            if (mHandler != null) {
                                Message message = new Message();
                                message.what = 0x42;
                                message.arg2 = 3;
                                mHandler.sendMessage(message);
                            }
                        }
                    });
                }
            }
        });
        activityWatchSportBinding.jointType.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (watchSportTypeDialog == null) {
                    watchSportTypeDialog = new WatchSportTypeDialog(WatchSportActivity.this);
                    watchSportTypeDialog.setSelectListener(new WatchSportTypeDialog.SelectListener() {
                        @Override
                        public void selectData(int sex) {
                            type = sex;
                            activityWatchSportBinding.jointType.setText(sex + "");
                        }
                    });
                }
                if (!watchSportTypeDialog.isShowing()) {
                    watchSportTypeDialog.show();
                }
            }
        });
        /**
         * 开启app运动
         */
        activityWatchSportBinding.startWatchSport.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //检测手表是否可以开始运动
                EABleStartAppSports eaBleStartAppSports = new EABleStartAppSports();
                eaBleStartAppSports.setCheckSport(1);
                EABleManager.getInstance().startAppSport(eaBleStartAppSports, new GeneralCallback() {
                    @Override
                    public void result(boolean b) {
                        if (b) {
                            Log.e(TAG, "可以开始app运动");
                            EABleStartAppSports eaBleStartAppSports1 = new EABleStartAppSports();
                            eaBleStartAppSports1.setSportStatus(EABleSportStatus.start);
                            eaBleStartAppSports1.setAppSportType(EABleStartAppSports.AppSportType.ourdoor_walking);
                            eaBleStartAppSports1.setReportInterval(5);
                            EABleManager.getInstance().startAppSport(eaBleStartAppSports1, new GeneralCallback() {
                                @Override
                                public void result(boolean b) {
                                    if (b) {
                                        Log.e(TAG, "开启app运动成功");
                                        isStart = true;
                                        //间隔一秒发送数据
                                        if (mHandler != null) {
                                            mHandler.sendEmptyMessageDelayed(0x86, 1000);
                                        }
                                        return;
                                    } else {
                                        Log.e(TAG, "开启app运动失败");
                                    }
                                }

                                @Override
                                public void mutualFail(int i) {
                                    Log.e(TAG, "开启app运动失败:" + i);
                                }
                            });
                        } else {
                            Log.e(TAG, "不能开启app运动");
                        }
                    }

                    @Override
                    public void mutualFail(int i) {
                        Log.e(TAG, "检测app运动失败:" + i);
                    }
                });
            }
        });


    }

    @Override
    protected void onDestroy() {
        if (mHandler != null) {
            mHandler.removeCallbacksAndMessages(null);
            mHandler = null;
        }
        if (waitingDialog != null) {
            waitingDialog.dismiss();
            waitingDialog = null;
        }
        if (ageDialog != null) {
            ageDialog.destroyDialog();
            ageDialog = null;
        }
        if (watchSportTypeDialog != null) {
            watchSportTypeDialog.destroyDialog();
            watchSportTypeDialog = null;
        }
        super.onDestroy();
    }
}
